package com.duan.laugh.common.security.exception;

import com.duan.laugh.common.core.util.R;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import lombok.SneakyThrows;

/**
 * 异常序列化
 *
 * @author duanjw
 */
public class LaughOAuthExceptionJacksonSerializer extends StdSerializer<LaughOAuth2Exception> {

    protected LaughOAuthExceptionJacksonSerializer() {
        super(LaughOAuth2Exception.class);
    }

    @SneakyThrows
    @Override
    public void serialize(LaughOAuth2Exception value, JsonGenerator jgen, SerializerProvider serializerProvider) {
        jgen.writeStartObject();
        jgen.writeObjectField("code", R.FAIL);
        jgen.writeStringField("msg", value.getMessage());
        jgen.writeStringField("data", null);
        jgen.writeEndObject();
    }
}
